<?php
/**
 * Created by PhpStorm.
 * User: zys
 * Date: 2018/6/26
 * Time: 15:41
 */
namespace PhalconRest\Controllers;
use \PhalconRest\Exceptions\HTTPException;
use PhalconRest\Models\Product;

class MessageController extends RESTController{


    private  $fields = ['itemid','catid','catidname','title','thumb','username'];


    public function get()
    {
//        $config = new \Phalcon\Config\Adapter\Php("config/area.php");
//        $areadata = $config->toArray();
        return $this->respond("");
    }

    /**
     * @param $id
     */
    public function getOne($id)
    {
        return $this->respond("");

    }

    public function post(){

        $userid = $this->request->getPost('userid');
        $itemid = $this->request->getPost('itemid');
        $area   = $this->request->getPost('area');
        $title  = $this->request->getPost('title');
        $mobile = $this->request->getPost('mobile');
        $drugid = $itemid ? ", drugid={$itemid} " : " , drugid='' ";
//        $sql = " insert into destoon_buy_6 set areaid={$areaid},title='".$title."',ditch='".$ditch."',truename='".$truename."',keyword='".$title."',mobile='".$mobile."',qq='".$qq."',telephone='".$telephone."',
//		introduce='".$introduce."',status=2,edittime=".time().",ip='".$DT_IP."',addtime=".time().",editdate='".date('Y-m-d',time())."',adddate='".date('Y-m-d',time())."',template='' {$drugid},source='{$source}'";
//        $res = $db->query($sql);
//        if($res){
//            $r = $db->get_one("SELECT itemid FROM destoon_buy_6 order by itemid desc limit 1");
//            $r = $r['itemid'];
//            $sql_up = " update destoon_buy_6 set linkurl='show-{$r}.html' where itemid={$r} ";
//            $db->query($sql_up);
//            $sql_data = " insert into destoon_buy_data_6 set itemid={$r},content='".$introduce."' ";
//            $buy_data =$db->query($sql_data);
//        }
//        // 单独处理产品内容页的留言提交
//        if($userid){
//            foreach($g_Area as $k=>$v){
//                if($v == $areaid)
//                    $areaname = $k;
//            }
//            $sql = " select username from destoon_company where userid=".$userid;
//            $g_user = $db->get_one($sql);
//            $introduce = "标题：".$title."<br />联系人：".$truename."<br />代理区域：".$quyu."<br />联系电话：".$mobile."<br />qq：".$qq."<br />内容：".$introduce."<br />";
//            $sqll = " insert into destoon_message set title='".$title."',content='".$introduce."',touser='".$g_user['username']."',addtime=".time().",ip='".$DT_IP."',status=3,targetid={$r},dailiurl='/daili/show-".$r.".html'";
//            $user_sql = $db->query($sqll);
//        }
    }

    public function delete($id){
        return array('Delete / stub');
    }

    public function put($id){
        return array('Put / stub');
    }

    public function patch($id){
        return array('Patch / stub');
    }



}